import Toast from "@/components/notice/Toast.vue";
import {h,render } from "vue";
import MessageBox from "@/components/notice/MessageBox.vue";
export function showMsg(msg,type,delay=1000){

    let vnode = h(Toast,{msg,type});

    let div = document.createElement('div');

    document.body.appendChild(div);

    render(vnode,div)
    
    if(delay){
        setTimeout(() =>{
            render(null,div);
            document.body.removeChild(div);
        },delay);
    }
}

export function showDialog(props){
    let div = document.createElement('div');
    document.body.appendChild(div);
    return new Promise((resolve, reject) => {
        const confirmCallback = () => {
          document.body.removeChild(div)    
          resolve(undefined)
        }
        const cancelCallback = () => {
          document.body.removeChild(div)    
          reject(undefined)
        }
        const vNode = h(MessageBox, {
          ...props,
          confirmCallback,
          cancelCallback
        })
        render(vNode, div)
    })
}